const Sequelize = require('sequelize');
module.exports = function (sequelize, DataTypes) {
  return sequelize.define('Article', {
    articleId: {
      field: 'article_id',
      autoIncrement: true,
      type: DataTypes.INTEGER.UNSIGNED,
      allowNull: false,
      primaryKey: true
    },
    title: {
      type: DataTypes.STRING(255),
      allowNull: true,
      comment: "文章标题"
    },
    userId: {
      field: 'user_id',
      type: DataTypes.STRING(20),
      allowNull: true,
      comment: "用户ID"
    },
    author: {
      type: DataTypes.STRING(50),
      allowNull: true,
      comment: "作者"
    },
    coverImage: {
      field: 'cover_image',
      type: DataTypes.STRING(255),
      allowNull: true,
      comment: "文章封面图片"
    },
    qrcodePath: {
      field: 'qrcode_path',
      type: DataTypes.STRING(255),
      allowNull: true,
      comment: "文章专属二维码地址"
    },
    isMarkdown: {
      field: 'is_markdown',
      type: DataTypes.TINYINT.UNSIGNED,
      allowNull: true,
      defaultValue: 1
    },
    content: {
      type: DataTypes.TEXT,
      allowNull: true,
      comment: "文章内容"
    },
    contentMd: {
      field: 'content_md',
      type: DataTypes.TEXT,
      allowNull: true,
      comment: "markdown版的文章内容"
    },
    top: {
      type: DataTypes.TINYINT.UNSIGNED,
      allowNull: true,
      defaultValue: 0,
      comment: "是否置顶"
    },
    categoryId: {
      field: 'category_id',
      type: DataTypes.INTEGER.UNSIGNED,
      allowNull: true,
      comment: "类型"
    },
    status: {
      type: DataTypes.TINYINT.UNSIGNED,
      allowNull: true,
      comment: "状态"
    },
    recommended: {
      type: DataTypes.TINYINT.UNSIGNED,
      allowNull: true,
      defaultValue: 0,
      comment: "是否推荐"
    },
    slider: {
      type: DataTypes.TINYINT.UNSIGNED,
      allowNull: true,
      defaultValue: 0,
      comment: "是否轮播"
    },
    sliderImg: {
      field: 'slider_img',
      type: DataTypes.STRING(255),
      allowNull: true,
      comment: "轮播图地址"
    },
    original: {
      type: DataTypes.TINYINT.UNSIGNED,
      allowNull: true,
      defaultValue: 1,
      comment: "是否原创"
    },
    description: {
      type: DataTypes.STRING(300),
      allowNull: true,
      comment: "文章简介，最多200字"
    },
    keywords: {
      type: DataTypes.STRING(200),
      allowNull: true,
      comment: "文章关键字，优化搜索"
    },
    comment: {
      type: DataTypes.TINYINT.UNSIGNED,
      allowNull: true,
      defaultValue: 1,
      comment: "是否开启评论"
    },
    createdAt: {
      field: 'create_time',
      type: DataTypes.DATE,
      allowNull: true,
      defaultValue: Sequelize.Sequelize.literal('CURRENT_TIMESTAMP'),
      comment: "添加时间"
    },
    updatedAt: {
      field: 'update_time',
      type: DataTypes.DATE,
      allowNull: true,
      defaultValue: Sequelize.Sequelize.literal('CURRENT_TIMESTAMP'),
      comment: "更新时间"
    }
  }, {
    sequelize,
    tableName: 'content_article',
    timestamps: false,
    indexes: [
      {
        name: "PRIMARY",
        unique: true,
        using: "BTREE",
        fields: [
          { name: "id" },
        ]
      },
    ]
  });
};
